<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qjsvalueiterator.cpp -->
  <title>QJSValueIterator  类 | Qt QML 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtqml-index.html">Qt QML</a></td><td ><a href="qtqml-module.html">C++ 类</a></td><td >QJSValueIterator</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtqml-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level1"><a href="#public-functions">公用函数</a></li>
<li class="level1"><a href="#details">详细信息</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QJSValueIterator类</h1>
<!-- $$$QJSValueIterator-brief -->
<p><a href="qjsvalueiterator.html">QJSValueIterator</a> 类为<a href="qjsvalue.html">QJSValue</a>提供了一个java风格的迭代器。<a href="#details">更多…</a></p>
<!-- @@@QJSValueIterator -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> 头文件：</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QJSValueIterator&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += qml</td></tr></table></div><ul>
<li><a href="qjsvalueiterator-members.html">所有成员的列表，包括继承的成员</a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">公用函数</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qjsvalueiterator.html#QJSValueIterator">QJSValueIterator</a></b>(const QJSValue &amp;<i>object</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qjsvalueiterator.html#dtor.QJSValueIterator">~QJSValueIterator</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qjsvalueiterator.html#hasNext">hasNext</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qjsvalueiterator.html#name">name</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qjsvalueiterator.html#next">next</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QJSValue </td><td class="memItemRight bottomAlign"><b><a href="qjsvalueiterator.html#value">value</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QJSValueIterator &amp;</td><td class="memItemRight bottomAlign"><b><a href="qjsvalueiterator.html#operator-eq">operator=</a></b>(QJSValue &amp;<i>object</i>)</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QJSValueIterator-description -->
<div class="descr">
<h2 id="details">详细信息</h2>
<p><a href="qjsvalueiterator.html">QJSValueIterator</a> 类为<a href="qjsvalue.html">QJSValue</a>提供了一个java风格的迭代器。</p>
<p><a href="qjsvalueiterator.html">QJSValueIterator</a> 构造函数接受一个 <a href="qjsvalue.html">QJSValue</a> 作为参数。构造完成后，迭代器位于属性序列的最开始。下面是如何迭代<a href="qjsvalue.html">QJSValue</a>的所有属性:</p>
<pre class="cpp">

  <span class="type"><a href="qjsvalue.html">QJSValue</a></span> object;
  <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
  <span class="type"><a href="qjsvalueiterator.html#QJSValueIterator">QJSValueIterator</a></span> it(object);
  <span class="keyword">while</span> (it<span class="operator">.</span>hasNext()) {
      it<span class="operator">.</span>next();
      <a href="../qtcore/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> it<span class="operator">.</span>name() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;: &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> it<span class="operator">.</span>value()<span class="operator">.</span>toString();
  }

</pre>
<p><a href="qjsvalueiterator.html#next">next</a>()将推进迭代器。<a href="qjsvalueiterator.html#name">name</a>() 和 <a href="qjsvalueiterator.html#value">value</a>() 函数返回最后跳过的项的名称和值。</p>
<p>注意，<a href="qjsvalueiterator.html">QJSValueIterator</a> 只迭 <a href="qjsvalue.html">QJSValue</a>自己的属性;也就是说，它不遵循原型链。你可以使用这样的循环跟随原型链:</p>
<pre class="cpp">

  <span class="type"><a href="qjsvalue.html">QJSValue</a></span> obj <span class="operator">=</span> <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>; <span class="comment">// the object to iterate over</span>
  <span class="keyword">while</span> (obj<span class="operator">.</span>isObject()) {
      <span class="type"><a href="qjsvalueiterator.html#QJSValueIterator">QJSValueIterator</a></span> it(obj);
      <span class="keyword">while</span> (it<span class="operator">.</span>hasNext()) {
          it<span class="operator">.</span>next();
          <a href="../qtcore/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> it<span class="operator">.</span>name();
      }
      obj <span class="operator">=</span> obj<span class="operator">.</span>prototype();
  }

</pre>
</div>
<p><b>参见</b><a href="qjsvalue.html#property">QJSValue::property</a>()。</p>
<!-- @@@QJSValueIterator -->
<div class="func">
<h2>成员函数文档</h2>
<!-- $$$QJSValueIterator[overload1]$$$QJSValueIteratorconstQJSValue& -->
<h3 class="fn" id="QJSValueIterator"><a name="QJSValueIterator"></a>QJSValueIterator::<span class="name">QJSValueIterator</span>(const <span class="type"><a href="qjsvalue.html">QJSValue</a></span> &amp;<i>object</i>)</h3>
<p>构造一个遍历<i>object</i>（对象）的迭代器。迭代器被设置在属性序列的前面(在第一个属性之前)。</p>
<!-- @@@QJSValueIterator -->
<!-- $$$~QJSValueIterator[overload1]$$$~QJSValueIterator -->
<h3 class="fn" id="dtor.QJSValueIterator"><a name="dtor.QJSValueIterator"></a>QJSValueIterator::<span class="name">~QJSValueIterator</span>()</h3>
<p>销毁迭代器。</p>
<!-- @@@~QJSValueIterator -->
<!-- $$$hasNext[overload1]$$$hasNext -->
<h3 class="fn" id="hasNext"><a name="hasNext"></a><span class="type">bool</span> QJSValueIterator::<span class="name">hasNext</span>() const</h3>
<p>如果迭代器前面至少有一个项(即迭代器<i>不</i> 在属性序列的后面)，则返回true;否则返回false。</p>
<p><b>参见 </b><a href="qjsvalueiterator.html#next">next</a>()。</p>
<!-- @@@hasNext -->
<!-- $$$name[overload1]$$$name -->
<h3 class="fn" id="name"><a name="name"></a><span class="type"><a href="../qtcore/qstring.html">QString</a></span> QJSValueIterator::<span class="name">name</span>() const</h3>
<p>返回使用<a href="qjsvalueiterator.html#next">next</a>()跳过的最后一个属性的名称。</p>
<p><b>参见 </b><a href="qjsvalueiterator.html#value">value</a>()。</p>
<!-- @@@name -->
<!-- $$$next[overload1]$$$next -->
<h3 class="fn" id="next"><a name="next"></a><span class="type">bool</span> QJSValueIterator::<span class="name">next</span>()</h3>
<p>将迭代器向前推进一个位置。如果迭代器前面至少有一个项(即迭代器还没有位于属性序列的后面)，则返回true;否则返回false。</p>
<p><b>参见 </b><a href="qjsvalueiterator.html#hasNext">hasNext</a>() 和 <a href="qjsvalueiterator.html#name">name</a>()。</p>
<!-- @@@next -->
<!-- $$$value[overload1]$$$value -->
<h3 class="fn" id="value"><a name="value"></a><span class="type"><a href="qjsvalue.html">QJSValue</a></span> QJSValueIterator::<span class="name">value</span>() const</h3>
<p>返回使用<a href="qjsvalueiterator.html#next">next</a>()跳过的最后一个属性的值。</p>
<p><b>请参考 </b><a href="qjsvalueiterator.html#name">name</a>()。</p>
<!-- @@@value -->
<!-- $$$operator=[overload1]$$$operator=QJSValue& -->
<h3 class="fn" id="operator-eq"><a name="operator-eq"></a><span class="type"><a href="qjsvalueiterator.html#QJSValueIterator">QJSValueIterator</a></span> &amp;QJSValueIterator::<span class="name">operator=</span>(<span class="type"><a href="qjsvalue.html">QJSValue</a></span> &amp;<i>object</i>)</h3>
<p>使迭代器对<i>object</i>进行操作。迭代器被设置在属性序列的前面(在第一个属性之前)。</p>
<!-- @@@operator= -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
